package com.cqc.googleplay.adapter;

import java.lang.reflect.TypeVariable;
import java.util.List;
import java.util.Random;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.cqc.googleplay.utils.ToastUtil;
import com.cqc.googleplay.view.randomlayout.StellarMap.Adapter;

public class StellarMapAdapter implements Adapter {

	private List<String> list;//集合中有33条数据
	private Context context;
	private int listPosition;
//	private TextView tv;
	public StellarMapAdapter(List<String> list,Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getGroupCount() {//有几组
		return 3;
	}

	@Override
	public int getCount(int group) {//一组有多少数据
		return 11;
	}

	@Override
	public View getView(int group, int position, View convertView) {
		final TextView tv = new TextView(context);
		listPosition = group*getCount(group) + position;
		tv.setText(list.get(listPosition));
		Random random = new Random();
		tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, random.nextInt(5)+15);//[15,20)
		
		int red = random.nextInt(150)+50;//[150,200)
		int green = random.nextInt(150)+50;//[150,200)
		int blue = random.nextInt(150)+50;//[150,200)
		int textColor = Color.rgb(red, green, blue);
		tv.setTextColor(textColor);
		
		//点击事件
		tv.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ToastUtil.showShortToast(tv.getText().toString());
			}
		});
		return tv;
	}

	@Override
	public int getNextGroupOnPan(int group, float degree) {
		return 0;
	}

	@Override
	public int getNextGroupOnZoom(int group, boolean isZoomIn) {
		return  (group + 1) % getGroupCount();// 确保循环显示  
	}

}
